<template>
  <div class="app-container">
    <el-form
      status-icon
      :rules="rules2"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="标题">
        <el-input v-model="title" auto-complete="off" />
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="content" auto-complete="off" />
      </el-form-item>
      <el-form-item label="图片">
        <el-upload
          class="upload-demo"
          action="/resource/news"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :on-success="list"
          :file-list="fileList"
          list-type="picture"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">
            只能上传jpg/png文件，且不超过500kb
          </div>
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add">提交</el-button>
        <el-button type="danger" @click="fanhui">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import service from '../../api/news'
// import { getTime } from "@/utils";
export default {
  name: '',
  data() {
    return {
      title: '',
      content: '',
      admin: localStorage.getItem('userId'),
      fileList: [],
      newsId: '',
      dialogImageUrl: ''
    }
  },
  methods: {
    fanhui() {
      this.$router.push('/news/index')
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    list(response) {
      this.fileList.push(response.url)
    },
    handlePreview(file) {
      this.fileList = file.url
    },
    add() {
      service
        .addBtn({
          title: this.title,
          content: this.content,
          images: this.fileList,
          admin: this.admin
        })
        .then((res) => {
          console.log(res)
        })
    }
  }
}
</script>
<style></style>;
